<template>
   <el-dialog   :visible.sync="visible" :title="title"  width="750px"  :before-close="handleClose">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="单位名称" prop="deptname">
        <el-input
          v-model="queryParams.deptname"
          placeholder="单位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd1"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['zyx:memberDevice:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['zyx:memberDevice:edit']"
        >修改</el-button>
      </el-col> -->

        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="memberDeviceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="企业" align="center" prop="sysDept.deptName" />
      <el-table-column label="科室/部门" align="center" prop="officename"  />
      <el-table-column label="设备" align="center" prop="zyxDevice.devicemodel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    </el-dialog>
<select-device-list ref="selectDeviceListRef"></select-device-list>
</template>

<script>
import { listMemberDevice,delMemberDevice} from "@/api/zyx/memberDevice";
import { listAllDept,  } from "@/api/system/dept";
import selectDeviceList from '../device/selectDeviceList.vue'

export default {
  name: "memberDeviceSrchList",
  components: {
    selectDeviceList,
  },
  data() {
    return {
      visible: false,
      title:'提示',
      memid:null,
      // 遮罩层
      loading: true,

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 成员基础信表格数据
      memberDeviceList: [],
      useofficeOptions:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberid: null,
        deptname: null,
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {


  },
  methods: {

    /** 查询成员基础信列表 */
    getList() {
      this.loading = true;
      this.queryParams.memberid=this.memid
      listMemberDevice(this.queryParams).then(response => {
        this.memberDeviceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        memberid: null,
        deviceid: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除选择的员工设备的数据项?', "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delMemberDevice(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
   handleClose(done) {
     done();
     },
     handleAdd1(){
        this.$parent.handleShowAdd(this.memid)
     }
  }
};
</script>
